package org.flexlancer.databases
{
	import flash.events.EventDispatcher;
	import flash.events.IEventDispatcher;

	public class dbServicePrice extends EventDispatcher
	{
		private static const TABLE:String = "serviceprice";
		
		public function dbServicePrice(target:IEventDispatcher=null)
		{
			super(target);
		}
		
		public static function List(condition:String = ""):Array{
			try{
				return DatabaseManager.Manager.Select(TABLE,null,condition);
			}catch(err:Error){
				throw err;
			}
			return null;
		}

		public static function Add(insertID:Number, servicePrice:Array):void{
			try{//customerid INTEGER PRIMARY KEY AUTOINCREMENT","customername TEXT", "customertype TEXT", "credit REAL"]);
				for each ( var singlePrice:Object in servicePrice ){
					//["refid TEXT","contacttype TEXT", "contactdetail TEXT"]
					var contObj:Object = new Object();
					contObj.refid = " 'SERV-"+insertID+"' ";
					contObj.pricetype = " '"+singlePrice.type+"' ";
					contObj.price = singlePrice.price;
					DatabaseManager.Manager.Insert(TABLE,contObj);
				}
				
				//DatabaseManager.Manager.Commit();
			}catch(err:Error){
				//DatabaseManager.Manager.Rollback();
				throw err;
			}
		}

		public static function Update(servicePrice:Array):void{
			try{//customerid INTEGER PRIMARY KEY AUTOINCREMENT","customername TEXT", "customertype TEXT", "credit REAL"]);
				for each ( var singlePrice:Object in servicePrice ){
					//["refid TEXT","contacttype TEXT", "contactdetail TEXT"]
					var contObj:Object = new Object();
					//contObj.refid = " 'SERV-"+insertID+"' ";
					contObj.pricetype = " '"+singlePrice.type+"' ";
					contObj.price = singlePrice.price;
					DatabaseManager.Manager.Update(TABLE,contObj, "servicepriceid = "+singlePrice.servicepriceid);
				}
				
				//DatabaseManager.Manager.Commit();
			}catch(err:Error){
				//DatabaseManager.Manager.Rollback();
				throw err;
			}
		}
		
		public static function Delete(condition:String = ""):void{
			try{
				DatabaseManager.Manager.Delete(TABLE,condition);
			}catch(err:Error){
				throw err;
			}
		} 
	}
}